package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.MenuCoupon;
import com.example.rbacmanage.service.app.MenuCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/background/menucoupon")
public class MenuCouponController {
    @Autowired
    private MenuCouponService menuCouponService;

    @GetMapping("/page")
    public Result page(MenuCoupon menuCoupon){
        return Result.success(menuCouponService.getPage( menuCoupon));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(menuCouponService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('background:menucoupon:add')")
    @PostMapping("/add")
    public Result save(@RequestBody MenuCoupon menuCoupon){
        menuCouponService.save(menuCoupon);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:menucoupon:update')")
    @PostMapping("/update")
    public Result update(@RequestBody MenuCoupon menuCoupon){
        menuCouponService.update(menuCoupon);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:menucoupon:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        menuCouponService.remove(ids);
        return Result.success();
    }
}
